<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="本文主要讲解 mall 整合 Elasticsearch 的过程，以实现商品信息在 Elasticsearch 中的导入、查询、修改、删除为例。  #👍 相关视频教程mall整合Elasticsearch实现商品搜索open in new window #项目使用框架介绍#Elasticsearch Elasticsearch 是一个分布式、可扩展、实时的搜索与数据分析引擎。 它能从项目一开始">
<meta property="og:type" content="article">
<meta property="og:title" content="mall整合Elasticsearch实现商品搜索">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/31ef856887ce.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="本文主要讲解 mall 整合 Elasticsearch 的过程，以实现商品信息在 Elasticsearch 中的导入、查询、修改、删除为例。  #👍 相关视频教程mall整合Elasticsearch实现商品搜索open in new window #项目使用框架介绍#Elasticsearch Elasticsearch 是一个分布式、可扩展、实时的搜索与数据分析引擎。 它能从项目一开始">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:27:18.000Z">
<meta property="article:modified_time" content="2024-02-02T15:06:26.588Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/31ef856887ce.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-02 23:06:26'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">mall整合Elasticsearch实现商品搜索</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:27:18.000Z" title="发表于 2024-01-21 17:27:18">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-02T15:06:26.588Z" title="更新于 2024-02-02 23:06:26">2024-02-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E6%9E%B6%E6%9E%84%E7%AF%87/">架构篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.1k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="mall整合Elasticsearch实现商品搜索"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>本文主要讲解 mall 整合 Elasticsearch 的过程，以实现商品信息在 Elasticsearch 中的导入、查询、修改、删除为例。</p>
</blockquote>
<h2 id="👍-相关视频教程"><a href="#👍-相关视频教程" class="headerlink" title="#👍 相关视频教程"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%F0%9F%91%8D-%E7%9B%B8%E5%85%B3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B">#</a>👍 相关视频教程</h2><p><a target="_blank" rel="noopener" href="https://t.zsxq.com/0einxu90G">mall整合Elasticsearch实现商品搜索open in new window</a></p>
<h2 id="项目使用框架介绍"><a href="#项目使用框架介绍" class="headerlink" title="#项目使用框架介绍"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8%E6%A1%86%E6%9E%B6%E4%BB%8B%E7%BB%8D">#</a>项目使用框架介绍</h2><h3 id="Elasticsearch"><a href="#Elasticsearch" class="headerlink" title="#Elasticsearch"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#elasticsearch">#</a>Elasticsearch</h3><blockquote>
<p>Elasticsearch 是一个分布式、可扩展、实时的搜索与数据分析引擎。 它能从项目一开始就赋予你的数据以搜索、分析和探索的能力，可用于实现全文搜索和实时数据统计。</p>
</blockquote>
<h4 id="Elasticsearch的安装和使用"><a href="#Elasticsearch的安装和使用" class="headerlink" title="#Elasticsearch的安装和使用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#elasticsearch%E7%9A%84%E5%AE%89%E8%A3%85%E5%92%8C%E4%BD%BF%E7%94%A8">#</a>Elasticsearch的安装和使用</h4><ol>
<li>下载Elasticsearch6.2.2的zip包，并解压到指定目录，下载地址：<a target="_blank" rel="noopener" href="https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-2-2">https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-2-2open in new window</a></li>
</ol>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_25-48daf958.png"></p>
<ol start="2">
<li>安装中文分词插件，在elasticsearch-6.2.2\bin目录下执行以下命令：elasticsearch-plugin install <a target="_blank" rel="noopener" href="https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip">https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.2/elasticsearch-analysis-ik-6.2.2.zip</a></li>
</ol>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_26-3dcb5bb5.png"></p>
<ol start="3">
<li>运行bin目录下的elasticsearch.bat启动Elasticsearch</li>
</ol>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_27-ba3cb8e0.png"></p>
<ol start="4">
<li>下载Kibana,作为访问Elasticsearch的客户端，请下载6.2.2版本的zip包，并解压到指定目录，下载地址：<a target="_blank" rel="noopener" href="https://artifacts.elastic.co/downloads/kibana/kibana-6.2.2-windows-x86_64.zip">https://artifacts.elastic.co/downloads/kibana/kibana-6.2.2-windows-x86_64.zipopen in new window</a></li>
</ol>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_28-021b8895.png"></p>
<ol start="5">
<li>运行bin目录下的kibana.bat，启动Kibana的用户界面</li>
</ol>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_29-0d7fe0a1.png"></p>
<ol start="6">
<li>访问<a target="_blank" rel="noopener" href="http://localhost:5601/">http://localhost:5601open in new window</a> 即可打开Kibana的用户界面</li>
</ol>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_30-362cad7b.png"></p>
<h3 id="Spring-Data-Elasticsearch"><a href="#Spring-Data-Elasticsearch" class="headerlink" title="#Spring Data Elasticsearch"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#spring-data-elasticsearch">#</a>Spring Data Elasticsearch</h3><blockquote>
<p>Spring Data Elasticsearch是Spring提供的一种以Spring Data风格来操作数据存储的方式，它可以避免编写大量的样板代码。</p>
</blockquote>
<h4 id="常用注解"><a href="#常用注解" class="headerlink" title="#常用注解"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3">#</a>常用注解</h4><h5 id="Document"><a href="#Document" class="headerlink" title="#@Document"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#document">#</a>@Document</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">//标示映射到Elasticsearch文档上的领域对象</span><br><span class="line">public @interface Document &#123;</span><br><span class="line">  //索引库名次，mysql中数据库的概念</span><br><span class="line">	String indexName();</span><br><span class="line">  //文档类型，mysql中表的概念</span><br><span class="line">	String type() default &quot;&quot;;</span><br><span class="line">  //默认分片数</span><br><span class="line">	short shards() default 5;</span><br><span class="line">  //默认副本数量</span><br><span class="line">	short replicas() default 1;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Id"><a href="#Id" class="headerlink" title="#@Id"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#id">#</a>@Id</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">//表示是文档的id，文档可以认为是mysql中表行的概念</span><br><span class="line">public @interface Id &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Field"><a href="#Field" class="headerlink" title="#@Field"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#field">#</a>@Field</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">public @interface Field &#123;</span><br><span class="line">  //文档中字段的类型</span><br><span class="line">	FieldType type() default FieldType.Auto;</span><br><span class="line">  //是否建立倒排索引</span><br><span class="line">	boolean index() default true;</span><br><span class="line">  //是否进行存储</span><br><span class="line">	boolean store() default false;</span><br><span class="line">  //分词器名次</span><br><span class="line">	String analyzer() default &quot;&quot;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">//为文档自动指定元数据类型</span><br><span class="line">public enum FieldType &#123;</span><br><span class="line">	Text,//会进行分词并建了索引的字符类型</span><br><span class="line">	Integer,</span><br><span class="line">	Long,</span><br><span class="line">	Date,</span><br><span class="line">	Float,</span><br><span class="line">	Double,</span><br><span class="line">	Boolean,</span><br><span class="line">	Object,</span><br><span class="line">	Auto,//自动判断字段类型</span><br><span class="line">	Nested,//嵌套对象类型</span><br><span class="line">	Ip,</span><br><span class="line">	Attachment,</span><br><span class="line">	Keyword//不会进行分词建立索引的类型</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Sping-Data方式的数据操作"><a href="#Sping-Data方式的数据操作" class="headerlink" title="#Sping Data方式的数据操作"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#sping-data%E6%96%B9%E5%BC%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C">#</a>Sping Data方式的数据操作</h4><h5 id="继承ElasticsearchRepository接口可以获得常用的数据操作方法"><a href="#继承ElasticsearchRepository接口可以获得常用的数据操作方法" class="headerlink" title="#继承ElasticsearchRepository接口可以获得常用的数据操作方法"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E7%BB%A7%E6%89%BFelasticsearchrepository%E6%8E%A5%E5%8F%A3%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%BE%97%E5%B8%B8%E7%94%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C%E6%96%B9%E6%B3%95">#</a>继承ElasticsearchRepository接口可以获得常用的数据操作方法</h5><p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_31-17948c33.png"></p>
<h5 id="可以使用衍生查询"><a href="#可以使用衍生查询" class="headerlink" title="#可以使用衍生查询"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E8%A1%8D%E7%94%9F%E6%9F%A5%E8%AF%A2">#</a>可以使用衍生查询</h5><blockquote>
<p>在接口中直接指定查询方法名称便可查询，无需进行实现，如商品表中有商品名称、标题和关键字，直接定义以下查询，就可以对这三个字段进行全文搜索。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 搜索查询</span><br><span class="line"> *</span><br><span class="line"> * @param name              商品名称</span><br><span class="line"> * @param subTitle          商品标题</span><br><span class="line"> * @param keywords          商品关键字</span><br><span class="line"> * @param page              分页信息</span><br><span class="line"> * @return</span><br><span class="line"> */</span><br><span class="line">Page&lt;EsProduct&gt; findByNameOrSubTitleOrKeywords(String name, String subTitle, String keywords, Pageable page);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>在idea中直接会提示对应字段</p>
</blockquote>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:06:12_arch_screen_32-d55bbbce.png"></p>
<h5 id="使用-Query注解可以用Elasticsearch的DSL语句进行查询"><a href="#使用-Query注解可以用Elasticsearch的DSL语句进行查询" class="headerlink" title="#使用@Query注解可以用Elasticsearch的DSL语句进行查询"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E4%BD%BF%E7%94%A8-query%E6%B3%A8%E8%A7%A3%E5%8F%AF%E4%BB%A5%E7%94%A8elasticsearch%E7%9A%84dsl%E8%AF%AD%E5%8F%A5%E8%BF%9B%E8%A1%8C%E6%9F%A5%E8%AF%A2">#</a>使用@Query注解可以用Elasticsearch的DSL语句进行查询</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@Query(&quot;&#123;&quot;bool&quot; : &#123;&quot;must&quot; : &#123;&quot;field&quot; : &#123;&quot;name&quot; : &quot;?0&quot;&#125;&#125;&#125;&#125;&quot;)</span><br><span class="line">Page&lt;EsProduct&gt; findByName(String name,Pageable pageable);</span><br></pre></td></tr></table></figure>

<h2 id="项目使用表说明"><a href="#项目使用表说明" class="headerlink" title="#项目使用表说明"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8%E8%A1%A8%E8%AF%B4%E6%98%8E">#</a>项目使用表说明</h2><ul>
<li><code>pms_product</code>：商品信息表</li>
<li><code>pms_product_attribute</code>：商品属性参数表</li>
<li><code>pms_product_attribute_value</code>：存储产品参数值的表</li>
</ul>
<h2 id="整合Elasticsearch实现商品搜索"><a href="#整合Elasticsearch实现商品搜索" class="headerlink" title="#整合Elasticsearch实现商品搜索"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E6%95%B4%E5%90%88elasticsearch%E5%AE%9E%E7%8E%B0%E5%95%86%E5%93%81%E6%90%9C%E7%B4%A2">#</a>整合Elasticsearch实现商品搜索</h2><h3 id="在pom-xml中添加相关依赖"><a href="#在pom-xml中添加相关依赖" class="headerlink" title="#在pom.xml中添加相关依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E5%9C%A8pom-xml%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%9B%B8%E5%85%B3%E4%BE%9D%E8%B5%96">#</a>在pom.xml中添加相关依赖</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--Elasticsearch相关依赖--&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;spring-boot-starter-data-elasticsearch&lt;artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<h3 id="修改SpringBoot配置文件"><a href="#修改SpringBoot配置文件" class="headerlink" title="#修改SpringBoot配置文件"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E4%BF%AE%E6%94%B9springboot%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6">#</a>修改SpringBoot配置文件</h3><blockquote>
<p>修改application.yml文件，在spring节点下添加Elasticsearch相关配置。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">data:</span><br><span class="line">  elasticsearch:</span><br><span class="line">    repositories:</span><br><span class="line">      enabled: true</span><br><span class="line">    cluster-nodes: 127.0.0.1:9300 # es的连接地址及端口号</span><br><span class="line">    cluster-name: elasticsearch # es集群的名称</span><br></pre></td></tr></table></figure>

<h3 id="添加商品文档对象EsProduct"><a href="#添加商品文档对象EsProduct" class="headerlink" title="#添加商品文档对象EsProduct"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E6%B7%BB%E5%8A%A0%E5%95%86%E5%93%81%E6%96%87%E6%A1%A3%E5%AF%B9%E8%B1%A1esproduct">#</a>添加商品文档对象EsProduct</h3><blockquote>
<p>不需要中文分词的字段设置成@Field(type &#x3D; FieldType.Keyword)类型，需要中文分词的设置成@Field(analyzer &#x3D; “ik_max_word”,type &#x3D; FieldType.Text)类型。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.nosql.elasticsearch.document;</span><br><span class="line"></span><br><span class="line">import org.springframework.data.annotation.Id;</span><br><span class="line">import org.springframework.data.elasticsearch.annotations.Document;</span><br><span class="line">import org.springframework.data.elasticsearch.annotations.Field;</span><br><span class="line">import org.springframework.data.elasticsearch.annotations.FieldType;</span><br><span class="line"></span><br><span class="line">import java.io.Serializable;</span><br><span class="line">import java.math.BigDecimal;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 搜索中的商品信息</span><br><span class="line"> * Created by macro on 2018/6/19.</span><br><span class="line"> */</span><br><span class="line">@Document(indexName = &quot;pms&quot;, type = &quot;product&quot;,shards = 1,replicas = 0)</span><br><span class="line">public class EsProduct implements Serializable &#123;</span><br><span class="line">    private static final long serialVersionUID = -1L;</span><br><span class="line">    @Id</span><br><span class="line">    private Long id;</span><br><span class="line">    @Field(type = FieldType.Keyword)</span><br><span class="line">    private String productSn;</span><br><span class="line">    private Long brandId;</span><br><span class="line">    @Field(type = FieldType.Keyword)</span><br><span class="line">    private String brandName;</span><br><span class="line">    private Long productCategoryId;</span><br><span class="line">    @Field(type = FieldType.Keyword)</span><br><span class="line">    private String productCategoryName;</span><br><span class="line">    private String pic;</span><br><span class="line">    @Field(analyzer = &quot;ik_max_word&quot;,type = FieldType.Text)</span><br><span class="line">    private String name;</span><br><span class="line">    @Field(analyzer = &quot;ik_max_word&quot;,type = FieldType.Text)</span><br><span class="line">    private String subTitle;</span><br><span class="line">    @Field(analyzer = &quot;ik_max_word&quot;,type = FieldType.Text)</span><br><span class="line">    private String keywords;</span><br><span class="line">    private BigDecimal price;</span><br><span class="line">    private Integer sale;</span><br><span class="line">    private Integer newStatus;</span><br><span class="line">    private Integer recommandStatus;</span><br><span class="line">    private Integer stock;</span><br><span class="line">    private Integer promotionType;</span><br><span class="line">    private Integer sort;</span><br><span class="line">    @Field(type =FieldType.Nested)</span><br><span class="line">    private List&lt;EsProductAttributeValue&gt; attrValueList;</span><br><span class="line"></span><br><span class="line">    //省略了所有getter和setter方法</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加EsProductRepository接口用于操作Elasticsearch"><a href="#添加EsProductRepository接口用于操作Elasticsearch" class="headerlink" title="#添加EsProductRepository接口用于操作Elasticsearch"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E6%B7%BB%E5%8A%A0esproductrepository%E6%8E%A5%E5%8F%A3%E7%94%A8%E4%BA%8E%E6%93%8D%E4%BD%9Celasticsearch">#</a>添加EsProductRepository接口用于操作Elasticsearch</h3><blockquote>
<p>继承ElasticsearchRepository接口，这样就拥有了一些基本的Elasticsearch数据操作方法，同时定义了一个衍生查询方法。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.nosql.elasticsearch.repository;</span><br><span class="line"></span><br><span class="line">import com.macro.mall.tiny.nosql.elasticsearch.document.EsProduct;</span><br><span class="line">import org.springframework.data.domain.Page;</span><br><span class="line">import org.springframework.data.domain.Pageable;</span><br><span class="line">import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 商品ES操作类</span><br><span class="line"> * Created by macro on 2018/6/19.</span><br><span class="line"> */</span><br><span class="line">public interface EsProductRepository extends ElasticsearchRepository&lt;EsProduct, Long&gt; &#123;</span><br><span class="line">    /**</span><br><span class="line">     * 搜索查询</span><br><span class="line">     *</span><br><span class="line">     * @param name              商品名称</span><br><span class="line">     * @param subTitle          商品标题</span><br><span class="line">     * @param keywords          商品关键字</span><br><span class="line">     * @param page              分页信息</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    Page&lt;EsProduct&gt; findByNameOrSubTitleOrKeywords(String name, String subTitle, String keywords, Pageable page);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加EsProductService接口"><a href="#添加EsProductService接口" class="headerlink" title="#添加EsProductService接口"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E6%B7%BB%E5%8A%A0esproductservice%E6%8E%A5%E5%8F%A3">#</a>添加EsProductService接口</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.service;</span><br><span class="line"></span><br><span class="line">import com.macro.mall.tiny.nosql.elasticsearch.document.EsProduct;</span><br><span class="line">import org.springframework.data.domain.Page;</span><br><span class="line"></span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 商品搜索管理Service</span><br><span class="line"> * Created by macro on 2018/6/19.</span><br><span class="line"> */</span><br><span class="line">public interface EsProductService &#123;</span><br><span class="line">    /**</span><br><span class="line">     * 从数据库中导入所有商品到ES</span><br><span class="line">     */</span><br><span class="line">    int importAll();</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据id删除商品</span><br><span class="line">     */</span><br><span class="line">    void delete(Long id);</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据id创建商品</span><br><span class="line">     */</span><br><span class="line">    EsProduct create(Long id);</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 批量删除商品</span><br><span class="line">     */</span><br><span class="line">    void delete(List&lt;Long&gt; ids);</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据关键字搜索名称或者副标题</span><br><span class="line">     */</span><br><span class="line">    Page&lt;EsProduct&gt; search(String keyword, Integer pageNum, Integer pageSize);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加EsProductService接口的实现类EsProductServiceImpl"><a href="#添加EsProductService接口的实现类EsProductServiceImpl" class="headerlink" title="#添加EsProductService接口的实现类EsProductServiceImpl"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E6%B7%BB%E5%8A%A0esproductservice%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBesproductserviceimpl">#</a>添加EsProductService接口的实现类EsProductServiceImpl</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.service.impl;</span><br><span class="line"></span><br><span class="line">import com.macro.mall.tiny.dao.EsProductDao;</span><br><span class="line">import com.macro.mall.tiny.nosql.elasticsearch.document.EsProduct;</span><br><span class="line">import com.macro.mall.tiny.nosql.elasticsearch.repository.EsProductRepository;</span><br><span class="line">import com.macro.mall.tiny.service.EsProductService;</span><br><span class="line">import org.slf4j.Logger;</span><br><span class="line">import org.slf4j.LoggerFactory;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.data.domain.Page;</span><br><span class="line">import org.springframework.data.domain.PageRequest;</span><br><span class="line">import org.springframework.data.domain.Pageable;</span><br><span class="line">import org.springframework.stereotype.Service;</span><br><span class="line">import org.springframework.util.CollectionUtils;</span><br><span class="line"></span><br><span class="line">import java.util.ArrayList;</span><br><span class="line">import java.util.Iterator;</span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 商品搜索管理Service实现类</span><br><span class="line"> * Created by macro on 2018/6/19.</span><br><span class="line"> */</span><br><span class="line">@Service</span><br><span class="line">public class EsProductServiceImpl implements EsProductService &#123;</span><br><span class="line">    private static final Logger LOGGER = LoggerFactory.getLogger(EsProductServiceImpl.class);</span><br><span class="line">    @Autowired</span><br><span class="line">    private EsProductDao productDao;</span><br><span class="line">    @Autowired</span><br><span class="line">    private EsProductRepository productRepository;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public int importAll() &#123;</span><br><span class="line">        List&lt;EsProduct&gt; esProductList = productDao.getAllEsProductList(null);</span><br><span class="line">        Iterable&lt;EsProduct&gt; esProductIterable = productRepository.saveAll(esProductList);</span><br><span class="line">        Iterator&lt;EsProduct&gt; iterator = esProductIterable.iterator();</span><br><span class="line">        int result = 0;</span><br><span class="line">        while (iterator.hasNext()) &#123;</span><br><span class="line">            result++;</span><br><span class="line">            iterator.next();</span><br><span class="line">        &#125;</span><br><span class="line">        return result;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void delete(Long id) &#123;</span><br><span class="line">        productRepository.deleteById(id);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public EsProduct create(Long id) &#123;</span><br><span class="line">        EsProduct result = null;</span><br><span class="line">        List&lt;EsProduct&gt; esProductList = productDao.getAllEsProductList(id);</span><br><span class="line">        if (esProductList.size() &gt; 0) &#123;</span><br><span class="line">            EsProduct esProduct = esProductList.get(0);</span><br><span class="line">            result = productRepository.save(esProduct);</span><br><span class="line">        &#125;</span><br><span class="line">        return result;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void delete(List&lt;Long&gt; ids) &#123;</span><br><span class="line">        if (!CollectionUtils.isEmpty(ids)) &#123;</span><br><span class="line">            List&lt;EsProduct&gt; esProductList = new ArrayList&lt;&gt;();</span><br><span class="line">            for (Long id : ids) &#123;</span><br><span class="line">                EsProduct esProduct = new EsProduct();</span><br><span class="line">                esProduct.setId(id);</span><br><span class="line">                esProductList.add(esProduct);</span><br><span class="line">            &#125;</span><br><span class="line">            productRepository.deleteAll(esProductList);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public Page&lt;EsProduct&gt; search(String keyword, Integer pageNum, Integer pageSize) &#123;</span><br><span class="line">        Pageable pageable = PageRequest.of(pageNum, pageSize);</span><br><span class="line">        return productRepository.findByNameOrSubTitleOrKeywords(keyword, keyword, keyword, pageable);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加EsProductController定义接口"><a href="#添加EsProductController定义接口" class="headerlink" title="#添加EsProductController定义接口"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E6%B7%BB%E5%8A%A0esproductcontroller%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3">#</a>添加EsProductController定义接口</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.controller;</span><br><span class="line"></span><br><span class="line">import com.macro.mall.tiny.common.api.CommonPage;</span><br><span class="line">import com.macro.mall.tiny.common.api.CommonResult;</span><br><span class="line">import com.macro.mall.tiny.nosql.elasticsearch.document.EsProduct;</span><br><span class="line">import com.macro.mall.tiny.service.EsProductService;</span><br><span class="line">import io.swagger.annotations.Api;</span><br><span class="line">import io.swagger.annotations.ApiOperation;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.data.domain.Page;</span><br><span class="line">import org.springframework.stereotype.Controller;</span><br><span class="line">import org.springframework.web.bind.annotation.*;</span><br><span class="line"></span><br><span class="line">import java.util.List;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 搜索商品管理Controller</span><br><span class="line"> * Created by macro on 2018/6/19.</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@Api(tags = &quot;EsProductController&quot;, description = &quot;搜索商品管理&quot;)</span><br><span class="line">@RequestMapping(&quot;/esProduct&quot;)</span><br><span class="line">public class EsProductController &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private EsProductService esProductService;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;导入所有数据库中商品到ES&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;/importAll&quot;, method = RequestMethod.POST)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;Integer&gt; importAllList() &#123;</span><br><span class="line">        int count = esProductService.importAll();</span><br><span class="line">        return CommonResult.success(count);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;根据id删除商品&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;/delete/&#123;id&#125;&quot;, method = RequestMethod.GET)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;Object&gt; delete(@PathVariable Long id) &#123;</span><br><span class="line">        esProductService.delete(id);</span><br><span class="line">        return CommonResult.success(null);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;根据id批量删除商品&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;/delete/batch&quot;, method = RequestMethod.POST)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;Object&gt; delete(@RequestParam(&quot;ids&quot;) List&lt;Long&gt; ids) &#123;</span><br><span class="line">        esProductService.delete(ids);</span><br><span class="line">        return CommonResult.success(null);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;根据id创建商品&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;/create/&#123;id&#125;&quot;, method = RequestMethod.POST)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;EsProduct&gt; create(@PathVariable Long id) &#123;</span><br><span class="line">        EsProduct esProduct = esProductService.create(id);</span><br><span class="line">        if (esProduct != null) &#123;</span><br><span class="line">            return CommonResult.success(esProduct);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            return CommonResult.failed();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;简单搜索&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;/search/simple&quot;, method = RequestMethod.GET)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;CommonPage&lt;EsProduct&gt;&gt; search(@RequestParam(required = false) String keyword,</span><br><span class="line">                                                      @RequestParam(required = false, defaultValue = &quot;0&quot;) Integer pageNum,</span><br><span class="line">                                                      @RequestParam(required = false, defaultValue = &quot;5&quot;) Integer pageSize) &#123;</span><br><span class="line">        Page&lt;EsProduct&gt; esProductPage = esProductService.search(keyword, pageNum, pageSize);</span><br><span class="line">        return CommonResult.success(CommonPage.restPage(esProductPage));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="进行接口测试"><a href="#进行接口测试" class="headerlink" title="#进行接口测试"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E8%BF%9B%E8%A1%8C%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95">#</a>进行接口测试</h2><h3 id="将数据库中数据导入到Elasticsearch"><a href="#将数据库中数据导入到Elasticsearch" class="headerlink" title="#将数据库中数据导入到Elasticsearch"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E5%B0%86%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5%E5%88%B0elasticsearch">#</a>将数据库中数据导入到Elasticsearch</h3><p><img src="/undefined"></p>
<h3 id="进行商品搜索"><a href="#进行商品搜索" class="headerlink" title="#进行商品搜索"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E8%BF%9B%E8%A1%8C%E5%95%86%E5%93%81%E6%90%9C%E7%B4%A2">#</a>进行商品搜索</h3><p><img src="/undefined"></p>
<h2 id="项目源码地址"><a href="#项目源码地址" class="headerlink" title="#项目源码地址"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_07.html#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80">#</a>项目源码地址</h2><p><a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-06">https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-06</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/31ef856887ce.html">https://ko25891wan.gitlab.io/2024/01/31ef856887ce.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/bdace4359249.html" title="搞定Mall项目中的权限管理功能，弄懂这些问题就妥了！"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">搞定Mall项目中的权限管理功能，弄懂这些问题就妥了！</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/0a484e1ac50b.html" title="mall整合MongoDB实现文档操作"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">mall整合MongoDB实现文档操作</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%F0%9F%91%8D-%E7%9B%B8%E5%85%B3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B"><span class="toc-number">1.</span> <span class="toc-text">👍 相关视频教程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8%E6%A1%86%E6%9E%B6%E4%BB%8B%E7%BB%8D"><span class="toc-number">2.</span> <span class="toc-text">项目使用框架介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Elasticsearch"><span class="toc-number">2.1.</span> <span class="toc-text">Elasticsearch</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Elasticsearch%E7%9A%84%E5%AE%89%E8%A3%85%E5%92%8C%E4%BD%BF%E7%94%A8"><span class="toc-number">2.1.1.</span> <span class="toc-text">Elasticsearch的安装和使用</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Spring-Data-Elasticsearch"><span class="toc-number">2.2.</span> <span class="toc-text">Spring Data Elasticsearch</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3"><span class="toc-number">2.2.1.</span> <span class="toc-text">常用注解</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Document"><span class="toc-number">2.2.1.1.</span> <span class="toc-text">@Document</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Id"><span class="toc-number">2.2.2.</span> <span class="toc-text">@Id</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Field"><span class="toc-number">2.2.3.</span> <span class="toc-text">@Field</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Sping-Data%E6%96%B9%E5%BC%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C"><span class="toc-number">2.2.4.</span> <span class="toc-text">Sping Data方式的数据操作</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%BB%A7%E6%89%BFElasticsearchRepository%E6%8E%A5%E5%8F%A3%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%BE%97%E5%B8%B8%E7%94%A8%E7%9A%84%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C%E6%96%B9%E6%B3%95"><span class="toc-number">2.2.4.1.</span> <span class="toc-text">继承ElasticsearchRepository接口可以获得常用的数据操作方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%E8%A1%8D%E7%94%9F%E6%9F%A5%E8%AF%A2"><span class="toc-number">2.2.4.2.</span> <span class="toc-text">可以使用衍生查询</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-Query%E6%B3%A8%E8%A7%A3%E5%8F%AF%E4%BB%A5%E7%94%A8Elasticsearch%E7%9A%84DSL%E8%AF%AD%E5%8F%A5%E8%BF%9B%E8%A1%8C%E6%9F%A5%E8%AF%A2"><span class="toc-number">2.2.4.3.</span> <span class="toc-text">使用@Query注解可以用Elasticsearch的DSL语句进行查询</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E4%BD%BF%E7%94%A8%E8%A1%A8%E8%AF%B4%E6%98%8E"><span class="toc-number">3.</span> <span class="toc-text">项目使用表说明</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B4%E5%90%88Elasticsearch%E5%AE%9E%E7%8E%B0%E5%95%86%E5%93%81%E6%90%9C%E7%B4%A2"><span class="toc-number">4.</span> <span class="toc-text">整合Elasticsearch实现商品搜索</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%A8pom-xml%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%9B%B8%E5%85%B3%E4%BE%9D%E8%B5%96"><span class="toc-number">4.1.</span> <span class="toc-text">在pom.xml中添加相关依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9SpringBoot%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">4.2.</span> <span class="toc-text">修改SpringBoot配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E5%95%86%E5%93%81%E6%96%87%E6%A1%A3%E5%AF%B9%E8%B1%A1EsProduct"><span class="toc-number">4.3.</span> <span class="toc-text">添加商品文档对象EsProduct</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0EsProductRepository%E6%8E%A5%E5%8F%A3%E7%94%A8%E4%BA%8E%E6%93%8D%E4%BD%9CElasticsearch"><span class="toc-number">4.4.</span> <span class="toc-text">添加EsProductRepository接口用于操作Elasticsearch</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0EsProductService%E6%8E%A5%E5%8F%A3"><span class="toc-number">4.5.</span> <span class="toc-text">添加EsProductService接口</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0EsProductService%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBEsProductServiceImpl"><span class="toc-number">4.6.</span> <span class="toc-text">添加EsProductService接口的实现类EsProductServiceImpl</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0EsProductController%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3"><span class="toc-number">4.7.</span> <span class="toc-text">添加EsProductController定义接口</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E8%A1%8C%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95"><span class="toc-number">5.</span> <span class="toc-text">进行接口测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%86%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E6%95%B0%E6%8D%AE%E5%AF%BC%E5%85%A5%E5%88%B0Elasticsearch"><span class="toc-number">5.1.</span> <span class="toc-text">将数据库中数据导入到Elasticsearch</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E8%A1%8C%E5%95%86%E5%93%81%E6%90%9C%E7%B4%A2"><span class="toc-number">5.2.</span> <span class="toc-text">进行商品搜索</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80"><span class="toc-number">6.</span> <span class="toc-text">项目源码地址</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>